const readline = require('readline');
const rl = readline.createInterface({ input: process.stdin });
let input = [];

rl.on('line', line => input.push(line.trim()));
rl.on('close', () => {
  let idx = 0;
  const T = parseInt(input[idx++]);

  for (let t = 0; t < T; t++) {
    const n = parseInt(input[idx++]);
    const abilities = input[idx++].split(' ').map(Number);

    // 特殊情况：只有一个队伍，无需比赛
    if (n === 1) {
      console.log(0);
      continue;
    }

    // 队伍1的能力值
    const team1Ability = abilities[0];

    // 模拟锦标赛
    let teams = abilities.map((ability, index) => ({
      id: index,  // 0 表示队伍1
      ability: ability
    }));

    let wins = 0;

    // 进行淘汰赛，直到只剩一个队伍
    while (teams.length > 1) {
      let nextRound = [];
      let team1StillIn = false;

      // 每轮两两对决
      for (let i = 0; i < teams.length; i += 2) {
        const teamA = teams[i];
        const teamB = teams[i + 1];

        // 能力值高的获胜
        const winner = teamA.ability > teamB.ability ? teamA : teamB;
        nextRound.push(winner);

        // 检查队伍1是否参与了这场比赛并获胜
        if (teamA.id === 0 || teamB.id === 0) {
          if (winner.id === 0) {
            wins++;  // 队伍1获胜
            team1StillIn = true;
          }
        }
      }

      teams = nextRound;
      
      // 如果队伍1已经被淘汰，提前退出
      if (!team1StillIn) {
        break;
      }
    }

    console.log(wins);
  }
});

